package com.example.netty.util;

import com.example.netty.bean.ResMsg;
import com.example.netty.enums.MsgTypeEnum;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author : lichong
 * @description :
 * @Date Create in 22:04 2020/1/11
 * @Modified By :
 **/
public class DateUtils {

    /**
     * String 转成date格式
     * @param time
     * @param pattern
     * @return
     * @throws Exception
     */
    public static Date parseString2Date(String time, String pattern) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.parse(time);
    }

    /**
     * 获取当前时间字符串
     * @param pattern
     * @return
     */
    public static String getStringDate(String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(new Date());
    }

    /**
     * 获取当前时间字符串
     * @param pattern
     * @return
     */
    public static String getStringDate(String pattern, Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(date);
    }
}
